Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom parameters to structured tests #6055

Conversation

JacekDuszenko
Copy link
Contributor

Fixes: #5817

Description
Custom parameters can now be added to structured tests in form of yaml config list.

Custom parameters can now be added to structured tests in form of yaml config list.
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #6055 (e1691e8) into master (30fded0) will decrease coverage by 0.23%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6055      +/-   ##
==========================================
- Coverage   70.55%   70.32%   -0.24%     
==========================================
  Files         468      471       +3     
  Lines       18036    18082      +46     
==========================================
- Hits        12726    12716      -10     
- Misses       4375     4436      +61     
+ Partials      935      930       -5     
Impacted Files Coverage Δ
pkg/skaffold/schema/latest/v1/config.go 58.82% <ø> (ø)
pkg/skaffold/test/structure/structure.go 91.11% <100.00%> (+0.41%) ⬆️
pkg/skaffold/deploy/deploy_mux.go 61.70% <0.00%> (-4.21%) ⬇️
pkg/skaffold/deploy/resource/deployment.go 85.36% <0.00%> (-3.62%) ⬇️
pkg/skaffold/runner/v1/deploy.go 49.39% <0.00%> (-3.61%) ⬇️
pkg/skaffold/runner/runcontext/context.go 83.21% <0.00%> (-1.40%) ⬇️
pkg/skaffold/event/event.go 91.12% <0.00%> (-0.85%) ⬇️
pkg/skaffold/deploy/kustomize/kustomize.go 74.66% <0.00%> (-0.34%) ⬇️
pkg/skaffold/deploy/helm/deploy.go 78.45% <0.00%> (-0.24%) ⬇️
pkg/skaffold/deploy/kpt/kpt.go 81.12% <0.00%> (-0.21%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30fded0...e1691e8. Read the comment docs.

Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! A few small changes.

@@ -491,6 +491,10 @@ type TestCase struct {
// to run on that artifact.
// For example: `["./test/*"]`.
StructureTests []string `yaml:"structureTests,omitempty" skaffold:"filepath"`

// StructureTestArgs lists additional configuration arguments passed to `container-structure-test` binary.
// For example: `["--driver tar", "--no-color", "-q"]`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mention elsewhere in this review, we don't want to do arg parsing. But most long-form arguments support using an = so we should be able to use:

Suggested change
// For example: `["--driver tar", "--no-color", "-q"]`.
// For example: `["--driver=tar", "--no-color", "-q"]`.

@@ -86,7 +89,10 @@ func (cst *Runner) runStructureTests(ctx context.Context, out io.Writer, imageTa
for _, f := range files {
args = append(args, "--config", f)
}

for _, customArg := range cst.structureTestArgs {
splittedCustomArg := strings.Fields(customArg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We require the user to be responsible for splitting arguments properly. Otherwise we need to deal with quoting issues, and YAML already makes that hard enough. Docker uses this approach too.

@@ -94,6 +94,44 @@ func TestIgnoreDockerNotFound(t *testing.T) {
})
}

func TestCustomParams(t *testing.T) {
const (
imageName = "image:tag"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just inline this: you're using the string inline anyways further below.

workspace: tc.Workspace,
localDaemon: localDaemon,
imageIsLocal: imageIsLocal,
structureTestArgs: tc.StructureTestArgs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to move this up below line 51 with the structureTests to keep the parameters together. localDaemon and imageIsLocal are internal matters.

Comment on lines 106 to 109
expectedBaseCmd := "container-structure-test test -v warn --image " + imageName + " --config " + tmpDir.Path("test.yaml")
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver tar --force --no-color -q --save"))

structureTestArgs := []string{"--driver tar", "--force", "--no-color", "-q", "--save"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expectedBaseCmd := "container-structure-test test -v warn --image " + imageName + " --config " + tmpDir.Path("test.yaml")
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver tar --force --no-color -q --save"))
structureTestArgs := []string{"--driver tar", "--force", "--no-color", "-q", "--save"}
expectedBaseCmd := "container-structure-test test -v warn --image image:tag --config " + tmpDir.Path("test.yaml")
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver=tar --force --no-color -q --save"))
structureTestArgs := []string{"--driver=tar", "--force", "--no-color", "-q", "--save"}

imageName = "image:tag"
)

testutil.Run(t, "", func(t *testutil.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to have tests here for: nil and an empty array too.

@JacekDuszenko
Copy link
Contributor Author

@briandealwis Thanks for your comments! I'll address them shortly and submit an updated PR.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jun 22, 2021
@JacekDuszenko
Copy link
Contributor Author

@briandealwis I added a new commit addressing your remarks, feel free to re-review if you're free. Thanks

@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Jun 23, 2021
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jun 23, 2021
Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great — thanks!

- --driver=tar
- -q
- --no-color
- --test-report=TEST_REPORT_NAME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- --test-report=TEST_REPORT_NAME
- --test-report=TEST_REPORT_NAME

@briandealwis briandealwis merged commit c326595 into GoogleContainerTools:master Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support container-structure-test driver flag
5 participants